<?php
/**
 * Created by PhpStorm.
 * User: yangfan
 * Date: 2019/11/28
 * Time: 5:04 PM
 */

namespace App\BO\Order\OrderRollback;

use App\Entities\OrderEntity;
use App\ServicesNew\CouponService;
use Illuminate\Support\Facades\Log;

/**
 * 回退优惠券
 * Class CouponOrderRollback
 * @package App\BO\Order\OrderRollback
 */
class CouponOrderRollback implements IOrderRollback
{
    public static function handle(OrderEntity $order, \Closure $next)
    {
        // 1. 回退优惠券
        if ($couponCodeId = $order->getCouponCodeId()) {
            /** * @var  CouponService $couponService */
            $couponService = app(CouponService::class);
            $couponService->orderRollback($order);
            Log::info('订单' . $order->getId() . '：优惠券' . $couponCodeId . ' 回退成功');
        } else {
            Log::info('订单' . $order->getId() . '：末使用优惠券，不用回退');
        }

        return $next($order);
    }
}
